﻿using System.Web.WebPages;
using WebMatrix.WebData;

namespace Account
{
    /// <summary>
    /// Summary description for Confirm
    /// </summary>
    public static class Confirm
    {        
        public class Error
        {
            public ErrorMessage ConfirmAccount { get; set; }
            public Error()
            {
                ConfirmAccount = ErrorMessage.Nil;
            }

        }

        public static void Init(WebPageBase web)
        {
            Error error = web.Page.Errors = new Error();

            web.Page.Confirmed = false;

            var confirmationToken = web.Request["confirmationCode"];

            WebSecurity.Logout();
            if (!confirmationToken.IsEmpty())
            {
                if (WebSecurity.ConfirmAccount(confirmationToken))
                {
                    web.Page.Confirmed = true;                    
                }
                else
                {
                    error.ConfirmAccount = web.Error("Could not confirm your registration info");
                }
            }
        }
    }
}